class CNMDateUtils {
  /// 获取今天YMD
  ///
  static DateTime get today {
    final DateTime now = DateTime.now();
    return DateTime(now.year, now.month, now.day);
  }

  /// 获取明天YMD
  ///
  static DateTime get tomorrow {
    return today.add(const Duration(days: 1));
  }

  /// 判断时间是否为同一天
  ///
  /// first：比较的时间对象
  ///
  /// last：比较的时间对象
  ///
  static bool isSameDate(DateTime first, DateTime last) {
    return (first.year == last.year && first.month == last.month && first.day == last.day);
  }

  /// 去掉时分秒，返回YMD
  ///
  /// date：时间DateTime对象
  ///
  static DateTime? onlyYMD(DateTime? date) {
    if (date != null) {
      return DateTime(date.year, date.month, date.day);
    }
    return null;
  }

  /// date 是否在 pastDate 和 futureDate 之间 (并包含pastDate、futureDate)
  ///
  /// date：需要判断的时间对象
  ///
  /// pastDate：过去的时间对象
  ///
  /// futureDate：将来的时间对象
  ///
  static bool dateIsBetweenIn(
    DateTime date, {
    required DateTime pastDate,
    required DateTime futureDate,
  }) {
    final r1 = date.compareTo(pastDate);
    final r2 = date.compareTo(futureDate);
    if ((r1 == 1 || r1 == 0) && (r2 == -1 || r2 == 0)) {
      return true;
    }
    return false;
  }

  /// 这个月多少天
  ///
  /// year：年
  ///
  /// month：月
  ///
  static int getDaysInMonth(int year, int month) {
    return month < DateTime.monthsPerYear ? DateTime(year, month + 1, 0).day : DateTime(year + 1, 1, 0).day;
  }
}
